package com.example.roadeyeserver.util;

import com.example.roadeyeserver.result.Result;
import org.springframework.stereotype.Component;

@Component
public class ResultUtil {
    // 成功时调用的方法
    public static <T> Result<T> success(T data) {
        return new Result<>(200, "成功", data);
    }

    public static <T> Result<T> success() {
        return success(null);
    }

    // 失败时调用的方法
    public static <T> Result<T> fail(Integer code, String message) {
        return new Result<>(code, message, null);
    }

    public static <T> Result<T> fail(String message) {
        return fail(500, message);
    }

    public static <T> Result<T> fail() {
        return fail(500, "失败");
    }
}
